package demo1;

import javax.swing.*;
import javax.swing.text.ElementIterator;
import javax.swing.text.StyledEditorKit;

public class Test {

    public static void drawMap(Shape shape){
        shape.draw();
    }

    public static void main(String[] args) {
        Shape rect=new Rect();
        Shape cycle=new Cycle();
        Shape triangle=new Triangle();
        //Shape flower=new Flower();

        //多态能够简化if else的嵌套
        //同时方便后续增加实例
        Shape[] shapes={rect,rect,cycle,triangle,triangle};//,flower
        for (Shape shape:shapes){
            shape.draw();
        }

//        String[] strings={"Rect","Rect","Cycle","Triangle","Triangle"};
//        for (String x:strings){
//            if(x.equals("Rect")){
//                rect.draw();
//            }else if (x.equals("Cycle")){
//                cycle.draw();
//            }else {
//                triangle.draw();
//            }
//        }


    }
}
